#include "ml20gui.h"
#include "lang.h"

extern HWND hdialog;

DWORD read_language( )
{
    uint8_t clang[5] = { 0, 0, 0, 0, 0 };
    int buflen = 5;

    reg_read_string( "Language", clang, &buflen );

    return *((int*)clang);
}

static void write_language( DWORD lang )
{
    uint8_t clang[5] = { 0, 0, 0, 0, 0 };
    *((int*)clang) = lang;

    reg_write_string( "Language", clang, 5 );
}

DWORD set_language( DWORD lang )
{
    DWORD ret = 0;
    appname = "MSN Webcam Recorder - 1.2rc7";

    switch( lang ) {
    case LFRENCH:
        set_fr( );
        break;
    case LSPANISH:
        set_es( );
        break;
    case LPORT:
        set_pt( );
        break;
    case LDEUTSCH:
        set_de( );
        break;
    case LALBANIAN:
        set_sq( );
        break;
    case LENGLISH:
        set_en( );
        break;
    case LDUTCH:
        set_nl( );
        break;
    case LTURKISH:
        set_tr( );
        break;
    case LSWEDISH:
        set_sv( );
        break;
    default:
        set_en( );
        lang = LENGLISH;
        ret = LENGLISH;
        break;
    }
    if( hdialog ) {
        update_main_menu( hdialog );
        lvcolumn_text( hdialog, IDC_LIST, 0, str_name );
        lvcolumn_text( hdialog, IDC_LIST, 1, str_size );
        lvcolumn_text( hdialog, IDC_LIST, 2, str_date );
    }
    write_language( lang );
    return ret;
}
